#include <aversive.h>
#include <aversive/wait.h>
#include <uart.h>
#include <adc.h>

int main(void)
{

  // Turn interruptions ON
  sei();

  // Initialize UART
  uart_init();
  fdevopen(uart0_dev_send,uart0_dev_recv);
 
  // bla
  printf("\n\nRobotter 2008 - 102chute - MECA ADC TEST \n");
  printf("Compiled "__DATE__" at "__TIME__"\n");
  printf("\nBooting...\n");

  // Initialize ADC
  adc_init();

  // Set up led port
  DDRB = 0xFB;
  PORTB = 0x80;

  printf("\ndone.\n\n");
  
  int i;
  while(1)
  {
    uart0_send('\r');
    for(i=0;i<8;i++)
    {
      printf("ADC%d = %d ",i,
             adc_get_value( (MUX_ADC0+i)|ADC_REF_AVCC ));
    }
    printf("         ");


    // twiliting
    PORTB >>= 1;
    if(!PORTB) PORTB=0x80;
    wait_ms(100);
  }

  while(1) nop();

  return 0;
}
